package com.yt.controller;

import com.alibaba.fastjson.JSONObject;
import com.yt.common.Constants;
import com.yt.pojo.Author;
import com.yt.pojo.ReturnResult;
import com.yt.service.AuthorService;
import com.yt.util.EmptyUtils;
import com.yt.util.RedisUtil;
import com.yt.util.TokenUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@Api
public class HelloController {

    @Resource
    AuthorService authorService;

    @ApiOperation(value = "你好")
    @ResponseBody
    @GetMapping("/hello")
    public Author hello(@ApiParam(name="name",value="对话人",required=true)String name){
        return new Author(1,"name",null);
    }

    @ApiOperation(value = "查看所有作者")
    @ResponseBody
    @GetMapping("/authors")
    public List<Author> authors( ){
        return authorService.getAllAuthors();
    }


    @ApiOperation(value = "作者登录操作")
    @ResponseBody
    @GetMapping("/author")
    public ReturnResult<Author> authors(@ApiParam(name="name",value="作者姓名",required=true)String name ){
        return authorService.getAllAuthorByName(name);
    }

    @ApiOperation(value = "查看所有作者")
    @ResponseBody
    @GetMapping("/allauthor")
    public ReturnResult<List<Author>> authorsBytoken(@ApiParam(name="token",value="令牌",required=true)String token  ){

        return authorService.getAllAuthors(token);
    }



}